class Project < ActiveRecord::Base
  
  validates_presence_of :name
  
  belongs_to :company
  
  has_many :project_assignments, :dependent => :destroy
  has_many :users, :through => :project_assignments
  
  has_many :hours
  
  # Find projects by company
  def self.find_by_company(company_id, options = {})
    with_scope :find => options do 
      find(:all, :order => 'name DESC', :conditions => ['company_id = ?', company_id])
    end
  end
  
  # Find all active projects
  def self.active_projects
    find(:all, :conditions => ['active = ?', true])
  end
  
  # Find all dead projects
  def self.dead_projects
    find(:all, :conditions => ['active = ?', false])
  end
end
